/**
 * 
 */
package pt.inescid.components.api;

import java.util.List;

import pt.inescid.components.commons.Resources;
import pt.inescid.components.messages.ACKMsg;
import pt.inescid.components.messages.AvailabilityMsg;
import pt.inescid.components.messages.Task;
import pt.inescid.components.messages.TaskResult;
import pt.inescid.components.messages.UpdateMsg;
import rice.environment.Environment;
import rice.p2p.commonapi.Id;
import rice.p2p.commonapi.Message;
import rice.p2p.commonapi.NodeHandle;
import rice.pastry.PastryNode;

/**
 * @author Sergio Esteves (sesteves at gsd.inesc-id.pt)
 *
 */
public interface OverlayManagerI {
	public void updateResources(double cpu, double mem, double bw);
	
	public void updateResources();
	
	public int getNumAvailableNodes(String appID, int limit);
	
	public int distributeTasks(String appID, List<Task> tasks, Resources taskCost);
	
	public int sendResult(Id id, int jobHandler, int taskNumber, byte[] output, double workDone);
	
	public PastryNode getNode();
	
	public Environment getEnvironment();
	
	public boolean networkInitialized();
	
	public void joinNode(NodeHandle handle);
	
	public void leaveNode(NodeHandle handle);
	
	public void messageReceived(Id id, UpdateMsg message);
	
	public void messageReceived(Id id, ACKMsg message);
	
	public void messageReceived(Id id, Task message, long currentTime);
	
	public void messageReceived(Id id, TaskResult message, long currentTime);
	
	public void messageReceived(Id id, AvailabilityMsg message);
	
	public UpdateMsg buildUpdateMsg();
	
	public Id forwardMessage(Id id, Message message);
	
	public void cacheTaskResult(Id key, final byte[] result);
	
	public byte[] lookupCache(final Id lookupKey);
	
	public long getMaxStorage();
	
	public void setMaxStorage(long size);
}
